package com.ruoyi.merchant.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.merchant.domain.MerchantCouponBindings;
import com.ruoyi.merchant.service.IMerchantCouponBindingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商家优惠券绑定Controller
 * 
 * @author ruoyi
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/merchant/coupon_bindings")
public class MerchantCouponBindingsController extends BaseController
{
    @Autowired
    private IMerchantCouponBindingsService merchantCouponBindingsService;

    /**
     * 查询商家优惠券绑定列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:list')")
    @GetMapping("/list")
    public TableDataInfo list(MerchantCouponBindings merchantCouponBindings)
    {
        startPage();
        List<MerchantCouponBindings> list = merchantCouponBindingsService.selectMerchantCouponBindingsList(merchantCouponBindings);
        return getDataTable(list);
    }

    /**
     * 导出商家优惠券绑定列表
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:export')")
    @Log(title = "商家优惠券绑定", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MerchantCouponBindings merchantCouponBindings)
    {
        List<MerchantCouponBindings> list = merchantCouponBindingsService.selectMerchantCouponBindingsList(merchantCouponBindings);
        ExcelUtil<MerchantCouponBindings> util = new ExcelUtil<MerchantCouponBindings>(MerchantCouponBindings.class);
        util.exportExcel(response, list, "商家优惠券绑定数据");
    }

    /**
     * 获取商家优惠券绑定详细信息
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:query')")
    @GetMapping(value = "/{bindingId}")
    public AjaxResult getInfo(@PathVariable("bindingId") String bindingId)
    {
        return success(merchantCouponBindingsService.selectMerchantCouponBindingsByBindingId(bindingId));
    }

    /**
     * 新增商家优惠券绑定
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:add')")
    @Log(title = "商家优惠券绑定", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MerchantCouponBindings merchantCouponBindings)
    {
        return toAjax(merchantCouponBindingsService.insertMerchantCouponBindings(merchantCouponBindings));
    }

    /**
     * 修改商家优惠券绑定
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:edit')")
    @Log(title = "商家优惠券绑定", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MerchantCouponBindings merchantCouponBindings)
    {
        return toAjax(merchantCouponBindingsService.updateMerchantCouponBindings(merchantCouponBindings));
    }

    /**
     * 删除商家优惠券绑定
     */
    @PreAuthorize("@ss.hasPermi('merchant:coupon_bindings:remove')")
    @Log(title = "商家优惠券绑定", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bindingIds}")
    public AjaxResult remove(@PathVariable String[] bindingIds)
    {
        return toAjax(merchantCouponBindingsService.deleteMerchantCouponBindingsByBindingIds(bindingIds));
    }
}
